home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / qlib205.zip / QLIB.ZIP / INC / CALLP.INC < prev    next >
Text File  |  1997-02-08  |  2KB  |  90 lines

  1. callp macro a1:req,a2:vararg
  2.   local siz,noargs,cnt,a3,a4,cnt2,axused,_esp,destroy_eax,type2
  3.  
  4.   destroy_eax = 0
  5. ;;  destroy_eax = 1
  6. ;;if you would like EAX to be destroyed for speed when
  7. ;;widening arguments then let destroy_eax = 1
  8.  
  9.   axused = 0  ;this is set to 1 if eax is trashed
  10.   noargs = 0
  11.   for a3,<a2>
  12.     noargs = noargs+1
  13.   endm
  14.   cnt = noargs
  15.   _esp = noargs*4
  16.   repeat noargs
  17.     cnt2=0
  18.     for a4,<a2>
  19.       cnt2 = cnt2+1
  20.       if cnt2 eq cnt
  21.         a3 textequ <a4>
  22.       endif
  23.     endm
  24.     siz = type (a3)
  25.     if axused eq 1
  26.       ifidn a3,<eax>
  27.         .err <EAX is destroyed!>
  28.       endif   ;20
  29.       ifidn a3,<ax>
  30.         .err <EAX is destroyed!>
  31.       endif
  32.       ifidn a3,<al>
  33.         .err <EAX is destroyed!>
  34.       endif
  35.       ifidn a3,<ah>
  36.         .err <EAX is destroyed!>
  37.       endif
  38.     endif
  39.     ifidn %siz,%0
  40.       push a3
  41.     elseifidn %siz,%1
  42.       type2 = (opattr a3) and 16
  43.       if (type2) eq 16   ;;is it a register?
  44.         push dptr 0
  45.         mov [esp],a3         
  46.       else
  47.         push dptr 0
  48.         ife destroy_eax
  49.           push ax
  50.         else
  51.           axused = 1
  52.         endif
  53.         mov al,a3
  54.         ife destroy_eax
  55.           mov [esp+2],al   ;;+2 cause AX is on the stack
  56.           pop ax
  57.         else
  58.           mov [esp],al
  59.         endif
  60.       endif
  61.     elseifidn %siz,%2
  62.       push wptr 0
  63.       push a3
  64.     elseifidn %siz,%4
  65.       push a3  ;line 44
  66.     elseifidn %siz,%6   ;;FWORD  (pushed as a QWORD)
  67.       push wptr 0
  68.       push wptr (a3+4)
  69.       push dptr a3
  70.       _esp = _esp+4     ;;add 4 more bytes
  71.     elseifidn %siz,%8   ;;REAL 8 (or QWORD)
  72.       push dptr (a3+4)
  73.       push dptr a3
  74.       _esp = _esp+4     ;;add 4 more bytes
  75.     elseifidn %siz,%10  ;;REAL 10 (or TWORD)
  76.       push wptr (a3+8)
  77.       push dptr (a3+4)
  78.       push dptr a3
  79.       _esp = _esp+6     ;;add 6 more bytes
  80.     else
  81.       % echo Warning: sizeof( a3 ) unknown.  Argument will be pushed 'as is'.
  82.       push a3
  83.     endif
  84.     cnt = cnt - 1    ;;count backwards thru arguments for C calling convention
  85.   endm
  86.   call a1
  87.   add esp,_esp
  88. endm
  89.  
  90.